#include "MyIncludes.h"
#include "StringKey.h"

StringKey::StringKey(string value)
{
	this->value = value;
}
StringKey::StringKey ()
{
	// value is using std::string empty constructor.
}
StringKey::StringKey( const StringKey & stringkey ) 
{
	this->value = stringkey.value;
}
StringKey::~StringKey() 
{
}
int StringKey::Compare (const StringKey & s) 
{
	int res = value.compare(s.value);
	return res;
}
unsigned int StringKey::Hash()
{
	unsigned int hash;
	for (int i = 0; i < value.length(); ++i) {
		hash = (value[i]*(256^i)) % 2^16;
	}
	hash %= 2^16;
	return hash;
}

const StringKey * StringKey::Read()
{
	cin >> value ;
	return this ;
}

bool StringKey::isEmpty()
{
	return (Compare(StringKey(EMPTY_KEY)) == 0);
}
const StringKey & StringKey::operator=( const StringKey & other ) 
{
	this->value = other.value;
	return *this;
}
const string & StringKey::getKey () const
{
	return value;
}
istream & operator >> ( istream & in , StringKey & stringkey ) throw (char*)
{
	in >> stringkey.value ;
	if ( stringkey.value == "FreeAllElements" )
		throw "FreeAllElements" ;
	if ( stringkey.value == "PrintDictionary" )
		throw "PrintDictionary" ;
	return in;
}

